package ar.com.aterrizar.ui;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.windows.Window;
import org.uqbar.arena.windows.WindowOwner;

import ar.com.aterrizar.asientos.Asiento;
import ar.com.aterrizar.uimodels.TransaccionesModel;

public class TransaccionesWindow extends Window<TransaccionesModel>{

	public TransaccionesWindow(WindowOwner parent, TransaccionesModel model) {
		super(parent, model);
		this.getModelObject().search();
	}

	@Override
	public void createContents(Panel mainPanel) {
		this.setTitle("Aterrizar.com");
		
		new Label(mainPanel).bindValueToProperty("title");
		
		this.createResultsGrid(mainPanel);
		
		new Button(new Panel(mainPanel)) //
			.setCaption("Cerrar")
			.onClick(new MessageSend(this, "close"));
		
	}
	
	protected void createResultsGrid(Panel mainPanel) {
		Table<Asiento> table = new Table<Asiento>(mainPanel, Asiento.class);
		table.setHeigth(200).setWidth(450);
		table.bindItemsToProperty("asientos");
		
		this.describeResultsGrid(table);
	}
	
	protected void describeResultsGrid(Table<Asiento> table) {
		new Column<Asiento>(table)
			.setTitle("Salida")
			.setFixedSize(200)
			.bindContentsToTransformer(new FechaTransformer());

		new Column<Asiento>(table)
			.setTitle("Aerolinea")
			.setFixedSize(100)
			.bindContentsToProperty("aerolineaNombre");

		new Column<Asiento>(table)
			.setTitle("Vuelo")
			.setFixedSize(50)
			.bindContentsToProperty("codVuelo");

		new Column<Asiento>(table)
			.setTitle("Asiento")
			.setFixedSize(50)
			.bindContentsToProperty("numAsiento");
		
		new Column<Asiento>(table)
			.setTitle("Precio")
			.setFixedSize(50)
			.bindContentsToTransformer(new PrecioTransformer(this.getModelObject().getCliente()));
	}

}
